package net.gz01.wallet.web.controller.api.sdk.client.authForfadada;

import net.gz01.util.ZOLog;
import net.gz01.wallet.web.controller.api.sdk.client.common.FddClient;
import net.gz01.wallet.web.controller.api.sdk.util.crypt.MsgDigestUtil;
import net.gz01.wallet.web.controller.api.sdk.util.http.ClientMultipartFormPost;
import net.gz01.wallet.web.controller.api.sdk.util.http.HttpsUtil;

import java.util.HashMap;
import java.util.Map;

public class GetPersonVerifyUrl extends FddClient {
    public GetPersonVerifyUrl(String appId, String secret, String version, String url) {
        super(appId, secret, version, url);
    }


    /**
     * 获取个人实名认证的接口地址
     * @return
     */
    public String getPersonVerifyUrl() {
        return super.getUrl() + "get_person_verify_url.api";
    }

    /**
     * 获取个人实名认证地址
     * @date: 2018年12月23日
     * @param customer_id 客户编号 注册账号时返回
     * @param verified_way 实名认证套餐类型
     * @param page_modify 是否允许用户页面修改 1允许，2不允许
     * @param notify_url 回调地址
     * @param return_url 同步通知url
     * @param customer_name 姓名
     * @param customer_ident_type 证件类型 目前仅支持身份证
     * @param customer_ident_no 证件号码
     * @param mobile 手机号码
     * @param ident_front_path 证件正面照下载地址
     * @return
     */
    public String invokePersonVerifyUrl(String customer_id, String verified_way,
                                        String page_modify, String notify_url,
                                        String return_url, String customer_name,
                                        String customer_ident_type,String customer_ident_no,
                                        String mobile,String ident_front_path) {
        Map<String,String> params = new HashMap<String,String>();
        try {
            String timeStamp = HttpsUtil.getTimeStamp();
            String msgDigest;
            params.put("customer_id", customer_id);
            params.put("verified_way", verified_way);
            params.put("page_modify", page_modify);
            params.put("notify_url", notify_url);
            params.put("customer_name",customer_name);
            params.put("customer_ident_type",customer_ident_type);
            params.put("customer_ident_no",customer_ident_no);
            params.put("mobile",mobile);
            params.put("ident_front_path",ident_front_path);
            params.put("return_url", return_url);
            String[] sortforParameters= MsgDigestUtil.sortforParameters(params);
            msgDigest =MsgDigestUtil.getCheckMsgDigest(
                    super.getAppId(),super.getSecret(),
                    timeStamp, sortforParameters);
            params.put("app_id",super.getAppId());
            params.put("timestamp",timeStamp);
            params.put("v",super.getVersion());
            params.put("msg_digest",msgDigest);

            ZOLog.api.info("FDD -->获取个人实名接口上送:" + params.toString());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return ClientMultipartFormPost.doPost(this.getPersonVerifyUrl(), params,null);
    }
}
